package cn.com.nes.site.action.user;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.common.util.JsonUtil;
import cn.com.nes.common.util.SMSUtil;
import cn.com.nes.common.util.ValidCodeUtil;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.sms.VerCodeReq;
import cn.com.nes.site.module.service.H5Service;
import cn.com.nes.site.module.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller("user")
@RequestMapping("/user")
public class UserAction {

    @Resource
    private UserService service;

    @Resource
    private H5Service h5service;

    /**
     * 热链云 PC端 用户登录
     * @param request
     * @param response
     * @param modelMap
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/login")
    public @ResponseBody PageData login(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        DataReq req = req_Status.getReq();
        PageData res = service.login(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/addUsersLoginInfo")
    public @ResponseBody PageData addUsersLoginInfo(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        req.getReqData().put("username", req.getUinfo().getUsername());
        req.getReqData().put("password", req.getUinfo().getPassword());
        res = service.login(req);
        if (res.getRetCode() == 0) {
            req.getReqData().put("key", JsonUtil.getStriFromObj(res));
            res = h5service.addUsersLoginInfo(req);
        }
        return res;
    }

    //扫码登录
    @RequestMapping(method = RequestMethod.POST, value = "/getKeyByToken")
    public @ResponseBody PageData getKeyByToken(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        DataReq req = req_Status.getReq();
        PageData res = service.getKeyByToken(req);
        return res;
    }

    //查询平台使用用户
    @RequestMapping(method = RequestMethod.POST, value = "/getUsers")
    public @ResponseBody PageData getUsers(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getUsers(req);
        return res;
    }

    //查询个人信息
    @RequestMapping(method = RequestMethod.POST, value = "/getUserMesg")
    public @ResponseBody PageData getUserMesg(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getUserMesg(req);
        return res;
    }

    //修改用户信息
    @RequestMapping(method = RequestMethod.POST, value = "/updateUser")
    public @ResponseBody PageData updateUser(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.updateUser(req);
        return res;
    }

    //判断是否认证
    @RequestMapping(method = RequestMethod.POST, value = "/checkCret")
    public @ResponseBody PageData checkCret(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.checkCret(req);
        return res;
    }

    //保存营业执照信息
    @RequestMapping(method = RequestMethod.POST, value = "/saveBusinessLicense")
    public @ResponseBody PageData saveBusinessLicense(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveBusinessLicense(req);
        return res;
    }

    //保存用户信息
    @RequestMapping(method = RequestMethod.POST, value = "/saveUser")
    public @ResponseBody PageData saveUser(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveUser(req);
        return res;
    }

    //删除平台使用用户
    @RequestMapping(method = RequestMethod.POST, value = "/delUser")
    public @ResponseBody PageData delUser(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.delUser(req);
        return res;
    }

    //保存平台使用用户角色和权限
    @RequestMapping(method = RequestMethod.POST, value = "/saveRoleAndModel")
    public @ResponseBody PageData saveRoleAndModel(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveRoleAndModel(req);
        return res;
    }

    //删除平台使用用户角色和权限
    @RequestMapping(method = RequestMethod.POST, value = "/delRoleAndModel")
    public @ResponseBody PageData delRoleAndModel(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.delRoleAndModel(req);
        return res;
    }

    //查询获取用户角色列表
    @RequestMapping(method = RequestMethod.POST, value = "/getRoles")
    public @ResponseBody PageData getRoles(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getRoles(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getRoles_new")
    public @ResponseBody PageData getRoles_new(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getRoles_new(req);
        return res;
    }

    //查询获取用户功能模块列表
    @RequestMapping(method = RequestMethod.POST, value = "/getModels")
    public @ResponseBody PageData getModels(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getModels(req);
        return res;
    }

    //查询获取用户功能模块列表
    @RequestMapping(method = RequestMethod.POST, value = "/getModels_new")
    public @ResponseBody PageData getModels_new(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getModels_new(req);
        return res;
    }

    //根据上级行政区划代码查询
    @RequestMapping(method = RequestMethod.POST, value = "/getAreaInfo")
    public @ResponseBody PageData getAreaInfo(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getAreaInfo(req);
        return res;
    }

    //查询获取参数列表
    @RequestMapping(method = RequestMethod.POST, value = "/getParam")
    public @ResponseBody PageData getParam(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getParam(req);
        return res;
    }

    //保存平台使用参数
    @RequestMapping(method = RequestMethod.POST, value = "/saveParam")
    public @ResponseBody PageData saveParam(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveParam(req);
        return res;
    }

    //删除平台使用参数
    @RequestMapping(method = RequestMethod.POST, value = "/delParam")
    public @ResponseBody PageData delParam(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.delParam(req);
        return res;
    }

    //查询公司信息
    @RequestMapping(method = RequestMethod.POST, value = "/getCompany")
    public @ResponseBody PageData getCompany(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getCompany(req);
        return res;
    }

    //保存公司信息
    @RequestMapping(method = RequestMethod.POST, value = "/saveCompany")
    public @ResponseBody PageData saveCompany(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveCompany(req);
        return res;
    }

    //删除公司信息
    @RequestMapping(method = RequestMethod.POST, value = "/delCompany")
    public @ResponseBody PageData delCompany(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.delCompany(req);
        return res;
    }

    //获取长效管护token
    @RequestMapping(method = RequestMethod.POST, value = "/getCcToken")
    public @ResponseBody PageData getCcToken(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getCcToken(req);
        return res;
    }

    //保存部门信息
    @RequestMapping(method = RequestMethod.POST, value = "/saveDepartment")
    public @ResponseBody PageData saveDepartment(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.saveDepartment(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getRolelist")
    public @ResponseBody PageData getRolelist(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getRolelist(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getCompanyList")
    public @ResponseBody PageData getCompanyList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getCompanyList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getDepartmentList")
    public @ResponseBody PageData getDepartmentList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getDepartmentList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getProjectList")
    public @ResponseBody PageData getProjectList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getProjectList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getNesCompanyList")
    public @ResponseBody PageData getNesCompanyList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getNesCompanyList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getNesSbmcList")
    public @ResponseBody PageData getNesSbmcList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getNesSbmcList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getNesSbxhList")
    public @ResponseBody PageData getNesSbxhList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getNesSbxhList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getAppHome")
    public @ResponseBody PageData getAppHome(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getAppHome(req);
        return res;
    }

    //在线注册
    @RequestMapping(method = RequestMethod.POST, value = "/onlineReg")
    public @ResponseBody PageData onlineReg(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.onlineReg(req);
        return res;
    }


    //获取验证码
    @RequestMapping(method = RequestMethod.POST, value = "/sendValidCode")
    public @ResponseBody PageData getValidCode(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        String phone = (String) req.getReqData().get("phone");
        //验证手机号的唯一性
        if (service.checkPhone(phone)) {
            res.setRetCode(9);
            res.setRetMessage("该手机号已经绑定过用户！");
        } else {
            String validCode = ValidCodeUtil.generateCode(phone);
            VerCodeReq sms = SMSUtil.sendSMS_ALIYUN_REG(phone, validCode);
            if (sms != null) {
                service.InsertSmsCode(sms);
                res.setRetCode(0);
                res.setRetMessage("获取验证码成功！");
            } else {
                res.setRetCode(9);
                res.setRetMessage("获取验证码失败");
            }

        }
        return res;
    }

    //修改密码
    @RequestMapping(method = RequestMethod.POST, value = "/updatePassword")
    public @ResponseBody PageData updatePassword(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.updatePassword(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/updateMfepuser")
    public @ResponseBody PageData updateMfepuser(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.updateMfepuser(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getAgentFacturer")
    public @ResponseBody PageData getAgentFacturer(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getAgentFacturer(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getAgentFacturerWdl")
    public @ResponseBody PageData getAgentFacturerWdl(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getAgentFacturerWdl(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/delAgentFacturer")
    public @ResponseBody PageData delAgentFacturer(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.delAgentFacturer(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/addAgentFacturer")
    public @ResponseBody PageData addAgentFacturer(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.addAgentFacturer(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getLogs")
    public @ResponseBody PageData getLogs(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getLogs(req);
        return res;
    }

    //获取用户头像
    @RequestMapping(method = RequestMethod.GET, value = "/getUserPic")
    public @ResponseBody PageData getUserPic(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getUserPic(req);
        return res;
    }

    // 获取广告列表
    @RequestMapping(method = RequestMethod.GET, value = "/getAd")
    public @ResponseBody PageData getAd(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getAd(req);
        return res;
    }

    // 发放优惠券
    @RequestMapping(method = RequestMethod.POST, value = "/sendCoupon")
    public @ResponseBody PageData sendCoupon(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        PageData res;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.sendCoupon(req);
        return res;
    }

    //后台管理员注册公司
    @RequestMapping(method = RequestMethod.POST, value = "/userReg")
    public @ResponseBody PageData userReg(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, false);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.userReg(req);
        return res;
    }

    //系统日志记录登录用户列表，按照用户汇总
    @RequestMapping(method = RequestMethod.POST, value = "/userLoginLogCount")
    public @ResponseBody PageData userLoginLogCount(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.userLoginLogCount(req);
        return res;
    }

    //系统日志记录登录用户列表
    @RequestMapping(method = RequestMethod.POST, value = "/userLoginLogList")
    public @ResponseBody PageData userLoginLogList(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.userLoginLogList(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getRoomUseTypes")
    public @ResponseBody PageData getRoomUseTypes(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getRoomUseTypes(req);
        return res;
    }

    @RequestMapping(method = RequestMethod.POST, value = "/getLoadParam")
    public @ResponseBody PageData getLoadParam(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getLoadParam(req);
        return res;
    }

    // 查询公司用户
    @RequestMapping(method = RequestMethod.GET, value = "/getUsersInCompany")
    public @ResponseBody PageData getUsersInCompany(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getUsersInCompany(req);
        return res;
    }

    //查询门店列表
    @RequestMapping(method = RequestMethod.POST, value = "/getMerList")
    public @ResponseBody PageData getMerList(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.getMerList(req);
        return res;
    }

    /**
     * 查询与客户处于同一行政区划的客服信息 CSS CustomerServiceStaff 客户服务职员
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/getNearCSSInfo")
    @ResponseBody
    public PageData getNearCSSInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        List<Map<String, Object>> list = service.getNearCSSInfo(req);
        if (!list.isEmpty()) {
            res.setRecordcount(list.size());
            res.setPage(list);
            res.setRetCode(0);
            res.setRetMessage("操作成功！");
        } else {
            res.setRecordcount(list.size());
            res.setRetCode(0);
            res.setRetMessage("没有相关门店及人员信息！");
        }
        return res;
    }

    // 查询公司用户
    @RequestMapping(method = RequestMethod.POST, value = "/checkedUser")
    public @ResponseBody PageData checkedUser(HttpServletRequest request, HttpServletResponse response,
                                                    ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response, true);
        PageData res = new PageData();
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode());
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq();
        res = service.checkedUsers(req);
        return res;
    }

}
